import config from '../../config/index'
Page({
  data: {
    user_name: '',
    pass_word: ''
  },

  bindUserNameInput(e) {
    this.setData({ user_name: e.detail.value });
  },
  bindPasswordInput(e) {
    this.setData({ pass_word: e.detail.value });
  },
  async login() {
    try {
      const params = {
        user_name:this.data.user_name,
        pass_word:this.data.pass_word
      }
      wx.request({
        url: config.apiUrl + '/login',
        method: "POST",
        data: JSON.stringify(params),
        header: {
          'Content-Type': 'application/json'
        },
        success: function(res) {
              console.log("请求结果data", res.data)
              // 跳转到首页
              wx.navigateTo({
                url: 'pages/index/index',
              })
              console.log("跳转成功")
            },
            fail: function(err) {
              console.log("错误信息", err)
            }
      })
    } catch (error) {
      console.error(error);
      wx.showToast({
        title: '请求失败',
        icon: 'none'
      });
    }
  }
});